﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using mars_client.csharp;
using mars_client.gui.page;
using System.IO;
using mars_client.gui.window;
using mars_client.csharp.util;
using mars_client.csharp.model;
using mars_client.csharp.enums;
using mars_client.csharp.model.vo;
using mars_client.csharp.cache;
using mars_client.csharp.radar;
using mars_client.csharp.controller;

namespace mars_client
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        GuiCache guic = GuiCache.Instance;
        Radar r = Radar.Instance;
        public MainWindow()
        {
            InitializeComponent();
            guic.setGui("MainWindow", this);
            guic.setGui("ChatListPage", new ChatListPage());
            guic.setGui("ContactPage", new ContactPage());
            guic.setGui("SystemMessagePage", new SystemMessagePage());

            Controller controller = Controller.Instance;
            controller.router();
            this.Hide();

            LoginWindow lw = new LoginWindow();
            lw.Show();
        }
        public void DragWindow(object sender, MouseButtonEventArgs args)
        {
            this.DragMove();
        }

        private void CloseUp(object sender, MouseButtonEventArgs e)
        {
            Environment.Exit(0);
        }

        private void MinUp(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }
        private void touxiang_click(object sender, MouseButtonEventArgs e)
        {
            MessageCO messageCO = new MessageCO();
            messageCO.type = (int)RequestEnum.request.User;
            UserVO userVO = new UserVO();
            userVO.id = UserCache.Instance.userVO.id;
            messageCO.content = userVO;
            r.sendData(messageCO);
        }
        /// <summary>
        /// 创建人   : Cecil0o0
        /// 电子邮箱 : jiegithub@gmail.com
        /// 创建时间 : 2016-2-27
        /// 功能描述 : 会话图标点击事件
        /// </summary>
        private void Chat_click(object sender, MouseButtonEventArgs e)
        {
            if (chat.Source.ToString().IndexOf("chat.png") != -1)
            {
                chat.Source = SysUtil.generateImgSource(@"\resource\img\button\chat_select.png");
                friend.Source = SysUtil.generateImgSource(@"\resource\img\button\friend.png");
                if(guic.getGui("ChatListPage") != null)
                {
                    LeftFrame.Content = guic.getGui("ChatListPage");
                }
                else
                {
                    ChatListPage cl = new ChatListPage();
                    LeftFrame.Content = cl;
                    guic.setGui("ChatListPage", cl);
                }
            }
        }
        /// <summary>
        /// 创建人   : Cecil0o0
        /// 电子邮箱 : jiegithub@gmail.com
        /// 创建时间 : 2016-2-27
        /// 功能描述 : 联系人图标点击事件
        /// </summary>
        private void Contact_click(object sender, MouseButtonEventArgs e)
        {
            if (friend.Source.ToString().IndexOf("friend.png") != -1)
            {
                friend.Source = SysUtil.generateImgSource(@"\resource\img\button\friend_select.png");
                chat.Source = SysUtil.generateImgSource(@"\resource\img\button\chat.png");
                if(guic.getGui("ContactPage") != null)
                {
                    LeftFrame.Content = guic.getGui("ContactPage");
                }
                else
                {
                    ContactPage flp = new ContactPage();
                    LeftFrame.Content = flp;
                    guic.setGui("ContactPage", flp);
                }
            }
        }
        
        public void changeBtnStyle(string activeEl)
        {
            if (activeEl.Equals("chat"))
            {
                friend.Source = SysUtil.generateImgSource(@"\resource\img\button\friend.png");
                chat.Source = SysUtil.generateImgSource(@"\resource\img\button\chat_select.png");
            }
            else if (activeEl.Equals("friend"))
            {
                friend.Source = SysUtil.generateImgSource(@"\resource\img\button\friend_select.png");
                chat.Source = SysUtil.generateImgSource(@"\resource\img\button\chat.png");
            }
        }
    }
}
